<?php
if(!defined('inside')) die('You do not have permission to execute this file directly.');

/**
 * This will redirect you to the given address
 * @param String $page The adress, for example, blog/showpost/id:1
 */
function redirect($page) {
	$config = AkaiKiwi::loadLib('Config');
	header('Location:'.$config->get_item('basePath').'/'.$page);
}

/**
* This will redirect after some seconds
* @param String $page
* @param int $time The time in seconds to wait before redirection
*/
function refresh($page, $time) {
	$config = AkaiKiwi::loadLib('Config');
	header('refresh:'.$time.';url='.$config->get_item('basePath').'/'.$page);
}

/**
 * Creates a link with the given name, pointing to the given adress
 * @param String $name The text to display
 * @param String $controller The adress, for example, blog/showpost/id:1
 * @param Array $properties An array of key => value strings, representing the link properties.
 */
function anchor($name, $controller, $properties = array()) {
	$config = AkaiKiwi::loadLib('Config');
	$r = '<a ';
	foreach($properties as $k => $v) {
		$r .= ' '.$k.'="'.$v.'" ';
	}
	$r .= 'href="'.$config->get_item('basePath').'/'.$controller.'/" >'.$name.'</a>';
	return $r;
}

/**
 * Returns the base url of the framework.
 */
function base_url() {
	$config = AkaiKiwi::loadLib('Config');
	return $config->get_item('baseUrl').'/';
}

/**
 * Returns the base path of the framework, specified in the configuration file.
 */
function base_path() {
	$config = AkaiKiwi::loadLib('Config');
	return $config->get_item('basePath');
}

/**
* Initializes some javascript variables so you can use them in your included scripts.
* BASE_URL: Equivalent to base_url()
* BASE_PATH: Equivalent to base_path()
*/
function js_init() {
	return '<script type="text/javascript" language="javascript" charset="utf-8">var BASE_URL = "'.base_url().'";var BASE_PATH = "'.base_path().'";</script>'."\n";
}
